package com.moneywelcome.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

@Configuration
public class RedisConfig {
    @Autowired
    private RedisConnectionFactory redisConnectionFactory;


    @Bean("redisJsonTemplate")
    public RedisTemplate<String, Object> createRedisTemplate(){
        RedisTemplate<String, Object> rt = new RedisTemplate<>();
        rt.setConnectionFactory(redisConnectionFactory);
        rt.setKeySerializer(RedisSerializer.string());
        rt.setHashKeySerializer(RedisSerializer.string());
        rt.setValueSerializer(RedisSerializer.json());
        rt.setHashValueSerializer(RedisSerializer.json());
        return rt;
    }


}
